package io.lckgroup.modules.lck.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.lckgroup.common.utils.PageUtils;
import io.lckgroup.common.utils.R;
import io.lckgroup.modules.lck.entity.ShopFoodAuditEntity;
import io.lckgroup.modules.lck.service.ShopFoodAuditService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 菜品审核表
 *
 * @author srq
 * @email siruiqi@siruiqi.com
 * @date 2020-01-19 19:14:39
 */
@RestController
@RequestMapping("diancan/shopfoodaudit")
public class ShopFoodAuditController {
    @Autowired
    private ShopFoodAuditService shopFoodAuditService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("diancan:shopfoodaudit:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = shopFoodAuditService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * @param params 列表
     * @return
     */
    @RequestMapping("/listpage")
    @RequiresPermissions("diancan:shopfoodaudit:list")
    public R listpage(@RequestParam Map<String, Object> params) {
        IPage<Map<String, Object>> selectPage = shopFoodAuditService.selectPageByAuditState(params);
        PageUtils pageUtils = new PageUtils(selectPage.getRecords(), (int) selectPage.getTotal(), (int) selectPage.getSize(), (int) selectPage.getCurrent());
        return R.ok().put("page", pageUtils);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("diancan:shopfoodaudit:info")
    public R info(@PathVariable("id") Long id) {
        ShopFoodAuditEntity shopFoodAudit = shopFoodAuditService.getById(id);
        // ShopFoodEntity shopFood = shopFoodService.getById(shopFoodAudit.getFoodId());
        return R.ok().put("shopFoodAudit", shopFoodAudit);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("diancan:shopfoodaudit:save")
    public R save(@RequestBody ShopFoodAuditEntity shopFoodAudit) {
        shopFoodAuditService.save(shopFoodAudit);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("diancan:shopfoodaudit:update")
    public R update(@RequestBody ShopFoodAuditEntity shopFoodAudit) {
        shopFoodAuditService.updateById(shopFoodAudit);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("diancan:shopfoodaudit:delete")
    public R delete(@RequestBody Long[] ids) {
        shopFoodAuditService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * @param params
     * @return 审核菜品
     */
    @RequestMapping("/AuditFood")
    @RequiresPermissions("diancan:shopfoodaudit:update")
    public R AuditFood(@RequestParam Map<String, Object> params) {
        shopFoodAuditService.AuditFood(params);
        return R.ok();
    }


    /**
     * @param ids
     * @return 批量审核
     */
    @RequestMapping("/passAuditBatch")
    @RequiresPermissions("diancan:shopfoodaudit:update")
    public R passAuditBatch(@RequestBody Long[] ids) {
        shopFoodAuditService.BatchAudit(ids);
        return R.ok();
    }


}
